package com.tuanzi.loan.business.repository.compensation.impl;

import com.tuanzi.loan.business.repository.compensation.custom.CompensationCompanyInfoRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepositoryPlus;
import com.tuanzi.loan.vo.request.compensation.CompensationCompanyInfoRequest;
import com.tuanzi.loan.vo.response.compensation.CompensationCompanyInfoResponse;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanCompensationCompanyInfo.LOAN_COMPENSATION_COMPANY_INFO;

/**
 * @author caiwanlin
 * @create 2019-02-12 14:03
 */
public class CompensationCompanyInfoRepositoryImpl extends JOOQBaseRepositoryPlus implements CompensationCompanyInfoRepositoryCustom {
    @Override
    public Page<CompensationCompanyInfoResponse> list(CompensationCompanyInfoRequest searchRequest, Pageable pageable) {
        fields(LOAN_COMPENSATION_COMPANY_INFO.fields());
        eq(LOAN_COMPENSATION_COMPANY_INFO.COMPANY_TYPE,searchRequest.getCompanyType());
        contains(LOAN_COMPENSATION_COMPANY_INFO.COMPANY_NAME,searchRequest.getCompanyName());
        orderBy(LOAN_COMPENSATION_COMPANY_INFO.CREATE_TIME, Sort.Direction.DESC);
        return search(pageable,e->{
            CompensationCompanyInfoResponse response = new CompensationCompanyInfoResponse();
            response.setId(e.get(LOAN_COMPENSATION_COMPANY_INFO.ID));
            response.setCompanyType(e.get(LOAN_COMPENSATION_COMPANY_INFO.COMPANY_TYPE));
            response.setCompanyName(e.get(LOAN_COMPENSATION_COMPANY_INFO.COMPANY_NAME));
            response.setFeeRate(e.get(LOAN_COMPENSATION_COMPANY_INFO.FEE_RATE));
            response.setFixFee(e.get(LOAN_COMPENSATION_COMPANY_INFO.FIX_FEE));
            response.setType(e.get(LOAN_COMPENSATION_COMPANY_INFO.TYPE));
            response.setCreateTime(e.get(LOAN_COMPENSATION_COMPANY_INFO.CREATE_TIME));
            response.setCreator(e.get(LOAN_COMPENSATION_COMPANY_INFO.CREATOR));
            response.setUpdateTime(e.get(LOAN_COMPENSATION_COMPANY_INFO.UPDATE_TIME));
            response.setUpdator(e.get(LOAN_COMPENSATION_COMPANY_INFO.UPDATOR));
            return response;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_COMPENSATION_COMPANY_INFO;
    }
}
